define(function(require, exports, module){
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/easyui/easyloader.js");
	var AJAX = require("resource/js/component/ajax.js");
	var EUtil = require("resource/js/component/easyutil.js");
	var EC = require("resource/js/component/easycombobox.js");
	var dataDgutil = undefined;
	var dataConfig = {
			name:"配比数据",
			column:[[
					{field:'id',title:'主键ID',width:100,align:'center',height:50,hidden:true},
					{field:'upDate',title:'时间',width:125,align:'center',height:50,hidden:false},
					{field:'deviceId',title:'设备ID',width:50,align:'center',height:50,hidden:true},
					{field:'deviceName',title:'设备名称',width:60,align:'center',height:50,hidden:false},
					{field:'materialId',title:'材料类型',width:60,align:'center',height:50,hidden:true},
					{field:'materialName',title:'材料类型',width:60,align:'center',height:50,hidden:false},
					{field:'oilstoneRatioActual',title:'油石比',width:60,align:'center',height:50,hidden:false},
					{field:'aggregate1Actual',title:'骨料1',width:50,align:'center',height:50,hidden:false},
					{field:'aggregate2Actual',title:'骨料2',width:50,align:'center',height:50,hidden:false},
					{field:'aggregate3Actual',title:'骨料3',width:50,align:'center',height:50,hidden:false},
					{field:'aggregate4Actual',title:'骨料4',width:50,align:'center',height:50,hidden:false},
					{field:'aggregate5Actual',title:'骨料5',width:60,align:'center',height:50,hidden:false},
					{field:'aggregate6Actual',title:'骨料6',width:60,align:'center',height:50,hidden:false},
					{field:'powder1Actual',title:'粉料1',width:60,align:'center',height:50,hidden:false},
					{field:'powder2Actual',title:'粉料2',width:60,align:'center',height:50,hidden:false},
					{field:'powder3Actual',title:'粉料3',width:60,align:'center',height:50,hidden:false},
					{field:'powder4Actual',title:'粉料4',width:60,align:'center',height:50,hidden:false},
					{field:'asphalt1Actual',title:'沥青1',width:60,align:'center',height:50,hidden:false},
					{field:'asphalt2Actual',title:'沥青2',width:60,align:'center',height:50,hidden:false},
					{field:'asphalt3Actual',title:'沥青3',width:60,align:'center',height:50,hidden:false},
					{field:'asphalt4Actual',title:'沥青4',width:60,align:'center',height:50,hidden:false},
					{field:'asphalt5Actual',title:'沥青5',width:60,align:'center',height:50,hidden:false},
					{field:'additive1Actual',title:'外加剂1',width:70,align:'center',height:50,hidden:false},
					{field:'additive2Design',title:'外加剂2',width:70,align:'center',height:50,hidden:false},
					]]
	}
	
	var gradDgutil = undefined;
	var gradConfig = {
			name:"级配数据",
			column:[[
                    {field:'id',title:'主键ID',width:100,align:'center',height:50,hidden:true},
                    {field:'级配曲线',title:'级配曲线',width:100,align:'center',height:50,hidden:false,formatter: function(value,row,index){

                    	return "</input><a href='javascript:void(0)' row='"+JSON.stringify(row)+"' rowIndex='"+index+"' id='"+row.id+"' class='linkbtn showChart'>显示曲线</a>";
    				}},
                    {field:'createTime',title:'时间',width:100,align:'center',height:50,hidden:false},
				    {field:'blenderId',title:'搅拌机ID',width:100,align:'center',height:50,hidden:true},
                    {field:'materialId',title:'材料类型',width:100,align:'center',height:50,hidden:true},
                    {field:'materialName',title:'材料类型',width:100,align:'center',height:50,hidden:false},
                    {field:'pore0063',title:'0.063',width:100,align:'center',height:50,hidden:false},
                    {field:'pore0125',title:'0.125',width:100,align:'center',height:50,hidden:false},
                    {field:'pore025',title:'0.25',width:100,align:'center',height:50,hidden:false},
                    {field:'pore05',title:'0.5',width:100,align:'center',height:50,hidden:false},
                    {field:'pore1',title:'1',width:100,align:'center',height:50,hidden:false},
                    {field:'pore2',title:'2',width:100,align:'center',height:50,hidden:false},
                    {field:'pore4',title:'4',width:100,align:'center',height:50,hidden:false},
                    {field:'pore5',title:'5',width:100,align:'center',height:50,hidden:false},
                    {field:'pore63',title:'6.3',width:100,align:'center',height:50,hidden:false},
                    {field:'pore8',title:'8',width:100,align:'center',height:50,hidden:false},
                    {field:'pore10',title:'10',width:100,align:'center',height:50,hidden:false},
                    {field:'pore125',title:'12.5',width:100,align:'center',height:50,hidden:false},
                    {field:'pore14',title:'14',width:100,align:'center',height:50,hidden:false},
                    {field:'pore16',title:'16',width:100,align:'center',height:50,hidden:false},
                    {field:'pore20',title:'20',width:100,align:'center',height:50,hidden:false},
                    {field:'pore25',title:'25',width:100,align:'center',height:50,hidden:false},
            ]]
	}
	
	var initpage = function(){
		var sectionId = sessionStorage.getItem('sectionId');  //获取标段id
		if(sectionId == null){
			sectionId = 0;
		}
		AJAX.init().success(function(code,msg,data){
			EC.init({ ele:"#blenderIdSearch",valueField:'blendId',remote:true, textField:'blendName',

			}).load(data);
		}).error(function(code,msg,data){
		}).post(BASEPATH+'/dcs/asphalt/device/findBlenderBySectionId.htm',{sectionId:sectionId});
		
		$("#searchSectionId").val(sectionId);
		$("#dataDiv").show();
		$("#gradDiv").hide();
		dataDgutil = EUtil.ajaxDataGrid(datagridconfig);
		
		/*查询配比数据*/
		$("#dataBtn").on("click",function(){
			$(this).addClass("active").siblings().removeClass("active");
			$("#dataDiv").show();
			$("#gradDiv").hide();
			dataDgutil = EUtil.ajaxDataGrid(datagridconfig);
		})
		/*查询级配数据*/
		$("#gradBtn").on("click",function(){
			$(this).addClass("active").siblings().removeClass("active");
			$("#dataDiv").hide();
			$("#gradDiv").show();
			gradDgutil = EUtil.ajaxDataGrid(gradgridconfig);
		})
	}

	//显示曲线
	var showChart = function(target){
		using(["form"],function(){
			$("#editdlg").dialog({
				iconCls: 'icon-save',
				title:'级配曲线',
				href:BASEPATH+"/view/dcs/asphalt/asphaltData/asphaltGradationChart",
				onLoad:function(){
					var id = $(target).attr("id");
					var dateStart = $("#datetimeStartSearch").datebox("getValue");
					var dateEnd = $("#datetimeEndSearch").datebox("getValue");
					var workMax = new Array();
					var workMin = new Array();
					var typeName = new Array();
					var poreValue = new Array();
					//数据组装
					var row = jQuery.parseJSON($(target).attr("row"));
					var blenderId = row.blenderId;
					AJAX.init().success(function(code,msg,data){
						if(data != null){

						}
						var map={};
						map['1'] = row.pore1;
						map['2'] = row.pore2;
						map['4'] = row.pore4;
						map['0.5'] = row.pore05;
						map['5'] = row.pore5;
						map['8'] = row.pore8;
						map['10'] = row.pore10;
						map['14'] = row.pore14;
						map['16'] = row.pore16;
						map['20'] = row.pore20;
						map['0.25'] = row.pore025;
						map['25'] = row.pore25;
						map['0.063'] = row.pore0063;
						map['0.125'] = row.pore0125;
						map['12.5'] = row.pore125;
						map['6.3'] = row.pore63;
						for(var i=0;i<data.length;i++){
							workMax[i] = data[i].max;
							workMin[i] = data[i].min;
							typeName[i] = data[i].type;
						}
					   for (var i=0;i<typeName.length;i++){
						   poreValue.push(map[typeName[i].toString()])
					   }
						createChart(workMax,workMin,typeName,poreValue);
					}).error(function(code,msg,data){
					}).post(BASEPATH+'/dcs/asphalt/asphaltGradation/queryChartData.htm',{"blenderId":blenderId});
			    },
				buttons: [{
					text:'取消',
					addClass:'l-btn-red',iconCls:'icon-not',
					accessKey:{akey:18,mkey:67},
					handler:function(){
						$('#editdlg').dialog('close');
					}
				}]
			});
			$("#editdlg").dialog("open");
		});
    }
	
	function createChart(max,min,name,value){
		var myChart = echarts.init(document.getElementById("lineChart"));
	    var option = {
	        // 标题
	        title: {
	            text: '级配曲线'
	        },
	        tooltip: {
	            trigger: 'axis',
				formatter : function(params){
	            	$(".tooltips").remove();
					var res  =  '<div class="tooltips">';
					res += '<div>筛孔尺寸：'+params[0].axisValue+'</div>';
					for(var i=0;i<params.length;i++){
						res += '<div>'+params[i].seriesName+"："+params[i].data+'</div>';
					}
					res += '</div>';
					return res;
				}
	        },
	        //图例名
	        legend: {
	            data:['上限值','下限值','级配值']
	        },
	        grid: {
	            left: '3%',   //图表距边框的距离
	            right: '10%',
	            bottom: '3%',
	            containLabel: true
	        },
	        //x轴信息样式
	        xAxis: {
	        	name:"筛孔尺寸(mm)",
	            type: 'category',
	            data: name,
	            //坐标轴颜色
	            axisLine:{
	                lineStyle:{
	                    color:'red'
	                }
	            },
	        },

	        yAxis : [
	            {
	            	name:"级配值",
	                type : 'value',
	                axisLabel : {
	                    formatter: '{value}'
	                }
	            }
	        ],
	        series: [
	            {
	                name:'上限值',
	                type:'line',
	                symbol:'circle',
	                symbolSize:4,
	                color:['green'],
	                itemStyle:{
	                    normal:{
	                    	lineStyle:{
	                            width:2,
	                            type:'solid'  //'dotted'虚线 'solid'实线
	                        }
	                    }
	                },
	                data:max
	            },
	            {
	                name:'级配值',
	                type:'line',
//	                stack: '总量',
	                symbolSize:4,
	                color:['red'],
	                smooth:true,   //关键点，为true是不支持虚线的，实线就用true
	                itemStyle:{
	                    normal:{
	                        lineStyle:{
	                            width:2,
	                            type:'solid'  //'dotted'虚线 'solid'实线
	                        }
	                    }
	                },
	                data:value
	            },
	            {
	                name:'下限值',
	                type:'line',
	                symbolSize:4,
	                color:['blue'],
	                itemStyle:{
	                    normal:{
	                        lineStyle:{
	                            width:2,
	                            type:'solid'  //'dotted'虚线 'solid'实线
	                        }
	                    }
	                },
	                data:min
	            }
	        ]
	    };

	    myChart.setOption(option);
		//用于使chart自适应高度和宽度
		window.onresize = function () {
		    myChart.resize();
		};
	}
	
	var processDataInit = function(){
		$.ajax({
			type: 'POST',
			url: BASEPATH+"/dcs/event/saveProcessData.htm",
			data: {},
			success: function (data) {
				if(data.msg.length > 0){
					$.messager.alert('系统提示',data.msg,'info');
				}
			}
		});
	}
	
	module.exports = {
		trans:function(){
			var databuttons ={ 
				title:{
					_class:"",
					text:"沥青站配比数据列表"
				},
				btn:[
					 {
						 iconCls: 'icon-search',
						 url:'/dcs/asphalt/asphaltData/queryDataAsphaltBlenderByPage.htm',
						 text:"查询",
						 //addClass:'l-btn-display',
						 btnType: 'searchBtn',
						 handler: function(){dataDgutil.pager(1);}
					 }/*,
					 {
						 iconCls: 'icon-icon1_100',
						 addClass:'l-btn-display',
						 text:"当日统计",
						 url:'/dcs/event/saveProcessData.htm',
						 handler: processDataInit
					 }*/
				]};
			var gradbuttons ={ 
					title:{
						_class:"",
						text:"沥青站级配数据列表"
					},
					btn:[
						 {
							 iconCls: 'icon-search',
							 url:'/dcs/asphalt/asphaltGradation/queryAllAsphaltGradationByPage.htm',
							 text:"查询",
							 //addClass:'l-btn-display',
							 btnType: 'searchBtn',
							 handler: function(){gradDgutil.pager(1);}
						 }
					]};
			datagridconfig = {
					fitColumns:true,
					singleSelect:false,
					striped:true,
					autoRowHeight:false,
					fit: true,
					toolbar:databuttons,
					columns:dataConfig.column,
					eid:"datadg",
					url:BASEPATH+'/dcs/asphalt/asphaltData/queryDataAsphaltBlenderByPage.htm',
					args:"searchform"
			};
			gradgridconfig = {
					fitColumns:true,
					singleSelect:false,
					striped:true,
					autoRowHeight:false,
					fit: true,
					toolbar:gradbuttons,
					columns:gradConfig.column,
					eid:"graddg",
					url:BASEPATH+'/dcs/asphalt/asphaltGradation/queryAllAsphaltGradationByPage.htm',
					args:"searchform",
					onLoadSuccess: function(data){
						if(data.total>0){
							$("a.showChart").click(function(){ showChart(this); });
						}
					}
			};
			
			using(["parser","dialog","datagrid","combobox","textbox","datetimebox" ],function(){
				initpage();
			});
		}
	}
});
